//
//  XGHuoShanViewModel.swift
//  TodayNews
//
//  Created by monkey on 2020/4/4.
//  Copyright © 2020 itcast. All rights reserved.
//

import UIKit
import SwiftyJSON

class XGHuoShanViewModel
{
    private(set) var smallVideos = [XGSmallVideoModel]()
    
    func fetchSmallVideoList(completion: @escaping(Bool) -> Void) -> Void
    {
        guard let url = Bundle.main.url(forResource: "SmallVideoList.json", withExtension: nil),
            let data = try? Data(contentsOf: url) else {
                completion(false)
                return
        }
        
        let jsonObject = JSON(data)
        guard let feeds = jsonObject["feeds"].array else {
            completion(false)
            return
        }
        let videoList = feeds.compactMap({
            return XGSmallVideoModel.deserialize(from: $0.dictionaryObject)
        })
        smallVideos += videoList
        completion(true)
    }
}
